import request from '@/utils/request.js'

/**
 * 提交订单
 * @param {Object} orderData - 订单数据
 * @returns {Promise} - 返回Promise对象
 */
export function submitOrder(orderData) {
  return request({
    url: '/order/submit',
    method: 'POST',
    data: orderData
  })
}

/**
 * 获取订单详情
 * @param {string} orderId - 订单ID
 * @returns {Promise} - 返回Promise对象
 */
export function getOrderDetail(orderId) {
  return request({
    url: `/order/detail/${orderId}`,
    method: 'GET'
  })
}

/**
 * 分页查询订单列表
 * @param {Object} data - 查询参数
 * @returns {Promise} - 返回Promise对象
 */
export function getOrderPage(data) {
  return request({
    url: '/order/page',
    method: 'GET',
    data
  })
}

/**
 * 取消订单
 * @param {string} orderId - 订单ID
 * @param {string} cancelReason - 取消原因
 * @returns {Promise} - 返回Promise对象
 */
export function cancelOrder(orderId, cancelReason) {
  return request({
    url: `/order/cancel/${orderId}`,
    method: 'POST',
    data: {
      cancelReason
    }
  })
}


/**
 * 查询订单各状态和对应数量
 * @param {Object} data - 查询参数
 * @returns {Promise} - 返回Promise对象
 */
export function getOrderStatusCountList() {
  return request({
    url: '/order/getOrderStatusCountList',
    method: 'GET'
  })
}

/**
 * 创建微信支付订单
 * @param {string} orderId - 订单ID
 * @returns {Promise} - 返回Promise对象
 */
export function createWechatPayOrder(orderId) {
  return request({
    url: `/order/pay/${orderId}`,
    method: 'POST'
  })
}

/**
 * 刷新微信支付状态
 * @param {string} orderId - 订单ID
 * @returns {Promise} - 返回Promise对象
 */
export function refreshPaymentStatus(orderId) {
  return request({
    url: `/order/refreshPaymentStatus/${orderId}`,
    method: 'POST'
  })
}
